<!DOCTYPE html>
<html>

<head>
    <title>Preview Display</title>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }
    </style>
	<script src='../libs/core/IZrowIfUVaXF.js'></script>
    <script src='../libs/core/VT3MIEkV8AKv.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/core/buckle.js'></script>
    <script src='../libs/core/ht-ui.js'></script>

    <script src='../libs/plugin/ht-edgetype.js'></script>
    <script src="../libs/plugin/ht-obj.js"></script>
    <script src='../libs/plugin/ht-form.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src='../libs/plugin/ht-animation.js'></script>

    <script src='../configs/htconfig.js'></script>

    <!-- <script src="../libs/china.js"></script> -->
    <script src="../libs/echarts.min.js"></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../libs/echarts.js'></script>
    <script src='../libs/buckle.js'></script>
    <script src='../libs/knU3sXefAa5Q.js'></script>
	
	<!--<script src='../../requestConfig/config.js'></script> -->
	<script src="../configs/urlConfig.js"></script>
	<script>
		var dataModel = new ht.DataModel();
		
		var array = window.location.href.split("&")[window.location.href.split("&").length-1].split("=");
		var httpArray = window.location.href.split("&");
		var httpIndex = httpArray.length - 1;
		var paramArray = httpArray[httpIndex].split("=");
		var stationId = paramArray[1]; //获取stationId
		var startDate;
		var endDate;
		
            function init(){
			
                //graphView = new ht.graph.GraphView(dataModel);
                //graphView.addToDOM();
				//dataModel = new ht.DataModel();
                graphView = new ht.graph.GraphView(dataModel);
                graphView.addToDOM();
                graphView.deserialize('displays/冀北/场站/场站.json', function(json, dm, gv, datas) {
					if(json.title) document.title = json.title;
                    if (json.a['json.background']) {
                        var bgJSON = json.a['json.background'];
                        if (bgJSON.indexOf('displays') === 0) {
                            var bgGv = new ht.graph.GraphView();
                            bgGv.deserialize(bgJSON);
                            bgGv.addToDOM();
                            graphView.addToDOM(bgGv.getView());
                        }
                        else if (bgJSON.indexOf('scenes') === 0) {
                            var bgG3d = new ht.graph3d.Graph3dView();
                            bgG3d.deserialize(bgJSON);
                            bgG3d.addToDOM();
                            graphView.addToDOM(bgG3d.getView());
                        }
                        graphView.handleScroll = function() {};
                    }
				
				   
					// 各时间选择器设置默认值
					// 获取当前时间时间戳（毫秒）
					var currentTime = Date.now();
					//将当前时间转换成时间格式
					var currentDate = new Date(parseInt(currentTime));
					var yy = currentDate.getFullYear();      //年
					var mm = currentDate.getMonth() + 1;     //月
					var dd = currentDate.getDate();          //日

					var endDate = yy + "-";
					if(mm < 10) endDate += "0";
					endDate += mm + "-";
					if(dd < 10) endDate += "0";
					endDate += dd;
					
					dm.getDataByTag('endDate').a('ht.value', endDate);
					
					//开始时间与结束时间相隔30天，转换成毫秒
					var offsetTime = 1000 * 3600 * 24 * 60 ;
					//将结束时间减去相隔时间即为开始时间
					var startTime = currentTime - offsetTime;
					startTime = new Date(parseInt(1577808000000));
					var yy = startTime.getFullYear();      //年
					var mm = startTime.getMonth() + 1;     //月
					var dd = startTime.getDate();          //日

					var startDate = yy + "-";
					if(mm < 10) startDate += "0";
					startDate += mm + "-";
					if(dd < 10) startDate += "0";
					startDate += dd;
					
					dm.getDataByTag('startDate').a('ht.value', startDate);
					
					
					startDate = dm.getDataByTag('startDate').a('ht.value');
					endDate = dm.getDataByTag('endDate').a('ht.value');
					
					dm.getDataByTag('tag1').s('select.width',0);
					dm.getDataByTag('tag2').s('select.width',0);
					dm.getDataByTag('tag3').s('select.width',0);
					dm.getDataByTag('tag4').s('select.width',0);
					dm.getDataByTag('tag5').s('select.width',0);
			
					
					getSixValue(stationId,startDate,endDate);//六项指标
					getOperateHoursAnalyse(stationId,startDate,endDate);//运行小时数
					getUnitLostTime(stationId,startDate,endDate);//损失电量分析
					getIndexOptimalUnit(stationId,startDate,endDate);//发电能力TOP10
                                        console.log(startDate + ":" + endDate)
					getBreakdownNumber(stationId,new Date(startDate).getTime(),new Date(endDate).getTime());//故障TOP10
					getWindResource(stationId,startDate,endDate);//风资源与发电量分析
					//getWeatherWarn();//天气预警列表
					getTree();//场站/机组树
					
                });
            }
			
			//获取平均可利用率、无故障运行时间等六项指标
			function getSixValue(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/sixValue?stationId=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
							if(result.data[0] || result.data[0] === 0){
								graphView.dm().getDataByTag('indicators_1').a('data',result.data[0]);
							}
							if(result.data[1] || result.data[1] === 0){
								graphView.dm().getDataByTag('indicators_2').a('data',result.data[1]);
							}
							if(result.data[2] || result.data[2] === 0){
								graphView.dm().getDataByTag('indicators_3').a('data',result.data[2]);
							}
							if(result.data[3] || result.data[3] === 0){
								graphView.dm().getDataByTag('indicators_4').a('data',result.data[3]);
							}
							if(result.data[4] || result.data[4] === 0){
								graphView.dm().getDataByTag('indicators_5').a('data',result.data[4]);
							}
							if(result.data[5] || result.data[5] === 0){
								graphView.dm().getDataByTag('indicators_6').a('data',result.data[5]);
							}
						}
					}
				});
			}
			
			//获取运行小时数
			function getOperateHoursAnalyse(id,start,end){
				let url = attributeConfig.url + "/epplatform/operateHours/operateHoursAnalyse?stationId=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
				
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data:JSON.stringify(),
					success:function(result){
						if(result.data){
							graphView.dm().getDataByTag('pie_operateHours').a('data',result.data);
						}
					}
				});
			}
			
			//损失电量分析
			function getUnitLostTime(id,start,end){
				let param = {
						  "stationId": id ,
						  "startTime": start ,
						  "endTime": end 
						}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/electricityAnalysis/unitLostElect",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							graphView.dm().getDataByTag('pie_unitLostTime').a('data',result.data);
						}
					}
				});
			}
			
			//发电能力TOP10
			function getIndexOptimalUnit(id,start,end){
				let param = {
							"stationId": id,
							"startTime": start,
							"endTime": end
							}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/regionSituationTrack/indexOptimalUnit",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							graphView.dm().getDataByTag('bar_optimalUnit').a('xAxisData',result.data.x);
							graphView.dm().getDataByTag('bar_optimalUnit').a('barData',result.data.y);
						}
					}
				});
			}
			
			
			//故障TOP10
			function getBreakdownNumber(id,start,end){
				let url = attributeConfig.url + "/epplatform/areaStateTrack/breakdownNumberAnalyse?stationId=" + id + "&"
			
				if(start){
					url = url + "startTime=" + start + "&";
				}
				if(end){
					url = url + "endTime=" + end + "&";
				}
                                console.log(url)
				$.ajax({
					url: url,
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
							graphView.dm().getDataByTag('bar_breakdownTop').a('yAxisData',result.data.xData);
							graphView.dm().getDataByTag('bar_breakdownTop').a('barData',result.data.yData);
						}
					}
				});
			}
			
			//风资源与发电量分析
			function getWindResource(id,start,end){
				let param = {
						  "stationId": id ,
						  "startTime": start ,
						  "endTime": end 
						}
				$.ajax({
					url: attributeConfig.url + "/epplatform/v1/regionSituationTrack/indexWindResourceAnalysis",
					type:"POST",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(param),
					success:function(result){
						if(result.data){
							graphView.dm().getDataByTag('windResource').a('xData',result.data.dateTime);//X轴月份
							graphView.dm().getDataByTag('windResource').a('barData',result.data.sumGeneration);//发电量
							graphView.dm().getDataByTag('windResource').a('lineData1',result.data.maxSpeed);//最大风速
							graphView.dm().getDataByTag('windResource').a('lineData2',result.data.avgSpeed);//平均风速
						}
					}
				});
			}
			
			//天气预警
			function getWeatherWarn(){
				$.ajax({
					url: attributeConfig.url + "/epplatform/areaStateTrack/weatherWarn",
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
						    let array = [];
					        result.data.map(((item, index)=> 
								{ array.push(Object.assign({},{info:item.dataTime + '\n' + item.warnArea + item.warnWather })) }))
							graphView.dm().getDataByTag('table_weatherWarn').a('ht.dataSource',array);
						}
					}
				});
			}
			
			//场站/机组树
			function getTree(){
				$.ajax({
					//url: attributeConfig.url + "/epplatform/v1/equipmentLedger/listEquipmentTree",
					url: attributeConfig.url + "/epplatform/areaStateTrack/getModelTree",
					type:"GET",
					contentType:"application/json",
					dataType:"json", 
					data: JSON.stringify(),
					success:function(result){
						if(result.data){
							//updateTreeData(result.data);
							graphView.dm().getDataByTag('listEquipmentTree').a('treedata',result.data);
						}
					}
				});
			}
			
			//遍历树、将树节点id变量化
			function updateTreeData(baseData){
                for(var i in baseData){
                    if(baseData[i].id){
                        baseData[i].id = "_" + baseData[i].id;
                        baseData[i].parentId = "_" + baseData[i].parentId;
                    }
                    if (Array.isArray(baseData[i].children) && baseData[i].children.length > 0) {
                        updateTreeData(baseData[i].children);
                    }
                }
            }
			
			
        </script>
    </head>
    <body onload='setTimeout(init, 300)'>
    </body>
</html>
